package viper.main;

public class ViperHeader {
	public static final byte RELAY = 1;
	public static final byte RECEIVE = 2;
	public static final byte CALL_SETUP = 3;
	
	public static final byte SETUP_MAKE_CALL = 31;
	public static final byte SETUP_ACCEPT_CALL = 32;
	public static final byte SETUP_REJECT_CALL = 33;
	public static final byte SETUP_END_CALL = 34;
	public static final byte SETUP_ERROR = 35;
	
	public static final byte CODE_232 = 41;
	public static final byte CODE_364 = 42;
	
	public static byte[] makeCallSetupPacket(byte setupType, byte[] payload)
	{
		int length = 0;
		if(payload!=null)
			length = payload.length;
		byte[] bytes = new byte[length+2];
		bytes[0] = CALL_SETUP;
		bytes[1] = setupType;
		System.arraycopy(payload, 0, bytes, 2, length);
		return bytes;
	}
	
	public static byte[] getPayloadFromSetupPacket(byte[] packet)
	{
		int length = packet.length;
		if(length>2)
		{
			byte[] payload = new byte[length-2];
			System.arraycopy(packet, 2, payload, 0, length);
			return payload;
		}
		else
		{
			return null;
		}
	}
	
}
